package demo;

import observer.Receiver;
import observer.Transmitter;

/**
 * 测试用的消息接收者
 */
public class MessageReceiver {

    public static final String TEST_ACTION = "test_action";

    public static final String TEST_AREA = "test_area";

    public static final String TEST_FLAG = "test_flag";

    private Receiver messageReceiver;

    public void init() {
        messageReceiver = new Receiver() {
            @Override
            public boolean receiver(Transmitter transmitter) {
                if (TEST_ACTION.equals(transmitter.getAction())){
                    System.out.println(transmitter.get(TEST_FLAG, "没有拿到消息时的默认消息！"));
                }
                return false;
            }
        };
        messageReceiver.addAction(TEST_ACTION);
        messageReceiver.register(TEST_AREA);
    }
}
